/**
 * 本地缓存，用来处理阅读记录的保存
 */
import { getItem, setItem } from '@/utils/storage'

const READ_KEY = 'MY_READ_RECORD'

export const getReadRecordList = () => {
  return getItem(READ_KEY)
}

export const findReadItem = (bookId) => {
  const data = getItem(READ_KEY) || {}

  return data[bookId]
}

export const addReadItem = ({ bookId, chapterId }) => {
  // 更新或者添加
  const data = getItem(READ_KEY) || {}
  const oldData = data[bookId] || {}
  data[bookId] = {
    ...oldData,
    bookId,
    chapterId
  }

  setItem(READ_KEY, data)
}

export const removeReadItem = (item) => {

}
